<template>
	<view class="box">
		<u-popup v-model="show" mode="bottom">
			<view class="msg">
				代理信息填写
			</view>
			<view class="" style="padding: 0 40rpx;">
				<u-form :model="form" ref="uForm">
					<u-form-item label="单位名称" label-width="180rpx"><u-input v-model="danwei"
							placeholder="请输入单位名称" /></u-form-item>
					<u-form-item label="姓名" label-width="180rpx"><u-input v-model="name"
							placeholder="请输入姓名" /></u-form-item>
					<u-form-item label="手机号码" label-width="180rpx"><u-input v-model="mobilex"
							placeholder="请输入手机号码" maxlength="11" /></u-form-item>
				
							<view class="" style="margin-top: 20rpx;">
								<u-radio-group v-model="values"  >
										<u-radio 
											@change="radioChange" 
											v-for="(item, index) in lis" :key="index" 
											:name="item.name"
											:disabled="item.disabled"
											shape="square"
											
										>
										<view class="d_f a_i_c" style="width: 100%;" >
											<view class="d_f a_i_c" >
												{{item.name}}
											<input v-model="qudao" style="width: 180rpx;"
													placeholder="请输入渠道ID" placeholder-style="font-size:26rpx"  @focus="onFocus" v-if="item.name=='渠道ID'" />
											</view>
								<!-- 			<view class="" v-if="item.name=='渠道ID'">
												<u-input v-model="miyao"
														placeholder="请输入渠道ID" placeholder-style="margin-left:82rpx" @focus="onFocus" />
											</view>
											<view class="" v-else > -->
										<!-- 		<u-upload :before-upload="beforeUpload" @after-read="afterRead" max-count="1" height="150" width="150" upload-text='上传'></u-upload> -->
								<!-- 		<u-upload
										   ref="upload"
										   max-count="1"
										   :header="header"
										   :action="action"
										 
										   @on-success="successUpload"
										   @on-remove="removeFile"
										   height="150" width="150" upload-text='上传'
										 ></u-upload> -->

											<!-- </view> -->
										</view>
											
											
										</u-radio>
									
									</u-radio-group>
							</view>
							<u-form-item label="秘钥" label-width="180rpx" v-if="values=='渠道ID'" ><u-input v-model="miyao"
									placeholder="请输入秘钥" /></u-form-item>
									
								
									<u-form-item label="推广码" label-width="180rpx" v-else>
										
										<u-upload
										   ref="upload"
										   max-count="1"
										   :header="header"
										   :action="action"
										 
										   @on-success="successUpload"
										   @on-remove="removeFile"
										   height="150" width="150" upload-text='上传'
										 ></u-upload>
									</u-form-item>
				
									
				</u-form>

			</view>
			<view class="botton d_f a_i_c j_c_c" @click="qd">
				确定
			</view>
			<view class="" style="height: 40rpx;">
				
			</view>
		</u-popup>
		<view class="" style="width: 100%;text-align: center;position: relative;">
			<image src="https://web.78keji.cn/images/ysh/quanyi.png" mode="widthFix" style="width:100%;"></image>
			<image src="https://web.78keji.cn/images/ysh/img_btn.png" mode="widthFix" style="width: 170rpx;position: absolute;left: 484rpx;top: 296rpx
				;" @click="youku"></image>
			<view class="d_f a_i_c"
				style="color: #808080;font-size: 32rpx;margin-top: 20rpx;position: absolute;left: 73rpx;top: 20rpx;">
				<image src="https://web.78keji.cn/images/ysh/icon.png" mode="widthFix" style="width:138rpx;"></image>

				<view class="" style="margin-left: 23rpx;margin-top: 20rpx;">
					<view class="" style="color: #333434;font-size: 32rpx;">
						省心权益中心
					</view>
					<view class="" style="text-align: left;color: #626161;padding-top: 22rpx;" v-if="!mobile">
						请登录...
					</view>
					<view class="" v-else style="text-align: left;color: #626161;padding-top: 22rpx;font-size: 26rpx;">
						{{mobile}}
					</view>
				</view>

			</view>


			<view class="d_f j_c_c " v-if="!mobile">
				<button class="login" type="default" open-type="getAuthorize" @getAuthorize="onGetAuthorize"
					scope='phoneNumber'
					style="position: absolute;width: 197rpx;height: 66rpx;top: 135rpx;left: 234rpx;opacity: 0;"></button>
			</view>
			<view class="" style="margin-top: -250rpx;">
				<image src="https://web.78keji.cn/images/ysh/dingdan.png" mode="widthFix" style="width:318rpx;"
					@click="youku"></image>
				<image src="https://web.78keji.cn/images/ysh/jl.png" mode="widthFix"
					style="width:318rpx;margin-left: 32rpx;" @click="youku"></image>
			</view>
			<image src="https://web.78keji.cn/images/ysh/2.png" mode="widthFix"
				style="width:700rpx;margin-top: 35rpx;" @click="telMobile"></image>
			<image src="https://web.78keji.cn/images/ysh/1.png" mode="widthFix" style="width:700rpx;margin-top: -8rpx;"
				@click="telMobile"></image>
			<image src="https://web.78keji.cn/images/ysh/3.png" mode="widthFix" style="width:700rpx;margin-top: -8rpx"
				@click="daili"></image>
		</view>




	</view>
</template>

<script>
	import {
		sendSms,
		checkSms,
		ljjList,
		wxLogins,
		ljjLq,
		getProType,
		openSignDecrypt,
		ljjStatusEdit,
		jyqList,
		jyqStatusEdit,
		getAliUser,
		decodeQrcode
	} from '../../api/index.js'
	import moment from '../../utils/moment.js'
	import md5 from '../../utils/md5.js'
	export default {
		data() {
			return {
				qudao:'',
				a:'',
			fileList: [],
				header: {
			      'Content-Type': 'multipart/form-data', //设置multipart/form-data格式
			     
			     },
				 action:'https://tcapi.sx2b2c.com/api/client_api/decodeQrcode',
	
						lis: [
								{
									name: '渠道ID',
									disabled: false
								},
							
								{
									name: '推广码',
									disabled: false
								}
							],
							// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
							values: '渠道ID',
				miyao: '',
				danwei: "",
				mobilex: "",
				name: '',
				listxs: [{
						id: 13,
						check: false
					},
					{
						id: 14,
						check: false
					},
					{
						id: 15,
						check: false
					},
				],
				zfbPrams: [],
				shuoming: false,
				content: '',
				border: true,
				showx: false,
				showr: false,
				listx: [

					{
						name: '工商银行微信立减金',
						id: '1931'
					},
					{
						name: '招商银行微信立减金',
						id: '3008'
					},
					{
						name: '农业银行微信立减金',
						id: '3009'
					},
					{
						name: '建设银行微信立减金',
						id: '3010'
					},
					{
						name: '中国银行微信立减金',
						id: '3011'
					},

				],
				// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
				value: '',
				shows: false,
				list: [{
					name: '优酷视频'
				}, ],
				current: 0,
				mobile: "",
				show: false,
				code: "",
				getCodeText: '获取验证码',
				getCodeBtnColor: "#ffffff",
				getCodeisWaiting: false,
				disabled: false,
				openid: "", //是否登录
				proType: '',
				xmlydata: [],
				tldata: [],
				ljjid: "", //立减金id
				idx: "", //省心会员券id
				flag: 0,
				idss: "",
				userid: "",
				result:'',
				image:'',
				look:''
			}
		},
		components: {

		},
		methods: {
			onFocus(){
				this.values='渠道ID'
				this.a=''
				this.image=''
			},
				// 选中某个单选框时，由radio时触发
					radioChange(e) {
						console.log(e);
						this.values = e
						if(e=='推广码'){
							this.miyao=''
							this.qudao=''
						}else{
					console.log(this.fileList)
					this.a=''
					this.image=''
						}
					},
					// 选中任一radio时，由radio-group触发
				
			qd(){
				uni.request({
				    url: 'https://tcapi.sx2b2c.com/api/client_api/bindAgency	', // 你的API地址
				    method: 'POST',
				    data: {
						company_name:this.danwei,
						nickname:this.name,
						mobile:this.mobilex,
						channel_id:this.qudao,
						secret_key:this.miyao,
						a:this.a,
						image_path:this.image,
				       mobile:	uni.getStorageSync('mobile'),
					   user_id:uni.getStorageSync('userid')
				    },
				    header: {
				        'content-type': 'application/x-www-form-urlencoded', // 默认值
				    },
				    success: (res) => {
						console.log(res)
						if(res.data.code==1){
							uni.showToast({
								icon: 'none',
								title:'成功',
								duration: 2000
							});
							uni.setStorageSync('token', res.data.data.token)	
							this.show=false
						
							this.result=true
							this.look=res.data.data.user_info.is_look_withdraw
							uni.navigateTo({
								url:'/pages/daili/daili?look='+this.look
							})
						}else{
							uni.showToast({
								icon: 'none',
								title: res.data.msg,
								duration: 2000
							});
						}
			
				    },
				    fail: (err) => {
				       uni.showToast({
				       	icon: 'none',
				       	title: err.msg,
				       	duration: 2000
				       });
				    }
				});
			
			},
			 getA(url) {
			  const parts = url.split('a=');
			  if (parts.length > 1) {
			    return parts[1]; // 返回问号后面的部分
			  }
			  return ''; // 如果没有问号，返回空字符串
			},
			cutStringBeforeChar(str, charToFind) {
			    const index = str.indexOf(charToFind);
			    if (index !== -1) {
			        return str.substring(0, index);
			    }
			    return str;
			}, 
		 getQueryString(url) {
		  const parts = url.split('a=');
		  if (parts.length > 1) {
		    return parts[1]; // 返回问号后面的部分
		  }
		  return ''; // 如果没有问号，返回空字符串
		},
		 containsAlipay(text) {
		    return text.includes("&");
		},
		 
		// 示例使用
	
		// 上传
		successUpload(data, index, lists, name) {
		   this.fileList.push(data.data.url)
		   this.image=data.data.url

		   if(this.containsAlipay(this.getQueryString(data.data.text))==true){
			    this.a= this.cutStringBeforeChar(this.getQueryString(data.data.text),'&')
		   }else{
			   this.a= this.getQueryString(data.data.text)
		   }
		   console.log(this.a)
		
		 },
		 // 移除
		 removeFile(index, lists, name) {
		   this.fileList.splice(index, 1)
		 },

			daili() {
				if (uni.getStorageSync('mobile')) {
					if(this.result==false){
						this.show = true
					}else{
						uni.navigateTo({
							url:'/pages/daili/daili?look='+this.look
						})
					}
					
				} else {
					uni.showToast({
						icon: 'none',
						title: '抱歉，请先登录',
						duration: 2000
					});
				}

			},
			youku() {

				if (uni.getStorageSync('mobile')) {
					uni.navigateTo({
						url: '/pages/yklq/yklq'
					})
				} else {
					uni.showToast({
						icon: 'none',
						title: '抱歉，请先登录',
						duration: 2000
					});
				}

			},
			telMobile() {
				uni.makePhoneCall({
					phoneNumber: '4008825010'
				})
			},
			onGetAuthorize() {
				uni.showLoading({
					title: "授权中",
					mask: true
				})
				my.getPhoneNumber({
					success: (res) => {
						let encryptedData = res.response;
						console.log(encryptedData)
						openSignDecrypt({
							encryptedData: JSON.parse(encryptedData).response,

						}).then((resx) => {
							console.log(resx)
							uni.hideLoading()

							uni.setStorageSync('mobile', resx.data.mobile)
							uni.setStorageSync('openid', resx.data.openid)
							this.mobile = resx.data.mobile
							this.openid = resx.data.openid
							
		// uni.request({
		// 	    url: 'https://tcapi.sx2b2c.com/api/client_api/isBindAgency', // 你的API地址
		// 	    method: 'POST',
		// 	    data: {
		// 	       mobile:	uni.getStorageSync('mobile'),
		// 		   user_id:uni.getStorageSync('userid')
		// 	    },
		// 	    header: {
		// 	        'content-type': 'application/x-www-form-urlencoded', // 默认值
		// 	    },
		// 	    success: (res) => {
		// 	        console.log('POST请求成功', res.data.data.res);
		// 			this.result=res.data.data.res
		// 			uni.setStorageSync('token', res.data.data.token)
		// 			if(this.result==true){
		// 				this.look=res.data.data.user_info.is_look_withdraw
		// 			}
						
		// 	    },
		// 	    fail: (err) => {
		// 	        console.error('POST请求失败', err);
		// 	    }
		// 	});
						})

					},
					fail: (res) => {
						console.log(res);
						uni.hideLoading()
						console.log('getPhoneNumber_fail');
					},
				});


			},

		},
		onLoad(option) {
			// my.navigateToMiniProgram ({
			//       appId: '2021004115620105',
			//       path: 'pages/youku_ljj2_full/youku_ljj2_full?fiter=777&a=4682bed6ab32a836d77fc5d3e29ef9b8&param=999',
			//       success: (res) => {
			//         console.log(JSON.stringify(res))
			//       },
			//       fail: (res) => {
			//         console.log(JSON.stringify(res))
			//       }
			//     });	
			if (uni.getStorageSync('mobile')) {
				this.mobile = uni.getStorageSync('mobile')
				uni.request({
				    url: 'https://tcapi.sx2b2c.com/api/client_api/isBindAgency', // 你的API地址
				    method: 'POST',
				    data: {
				       mobile:	uni.getStorageSync('mobile'),
					   user_id:uni.getStorageSync('userid')
				    },
				    header: {
				        'content-type': 'application/x-www-form-urlencoded', // 默认值
				    },
				    success: (res) => {
				        console.log('POST请求成功', res.data.data.res);
						this.result=res.data.data.res
						uni.setStorageSync('token', res.data.data.token)
						if(this.result==true){
							this.look=res.data.data.user_info.is_look_withdraw
						}
							
				    },
				    fail: (err) => {
				        console.error('POST请求失败', err);
				    }
				});
			}
			// 获取用户登录凭证code
			// 获取服务供应商
			uni.getProvider({
				service: 'oauth',
				success: function(res) {
					uni.login({
						provider: res.provider,
						success: function(loginRes) {
							console.log('uniapp登录凭证', loginRes.code);
							getAliUser({
								code: loginRes.code,
								pro_id: 50
							}).then((result) => {
								console.log(result.data.user_id)

								uni.setStorageSync('userid', result.data.user_id)
							})
						}
					});
				}
			});
	

			// getAliUser

		},
		watch: {

		},
		computed: {

		}
	}
</script>

<style scoped lang='scss'>
	.msg {
		width: 100%;
		height: 104rpx;
		background: #FF8D5B;
		border-radius: 11rpx 11rpx 0rpx 0rpx;
		font-size: 38rpx;
		font-weight: 600;
		color: #FFFFFF;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.botton {
		width: 600rpx;
		height: 79rpx;
		background: #FF8D5B;
		border-radius: 9rpx;
		color: white;
		margin: 0 auto;
		margin-top: 30rpx;
	}
</style>